package com.mzy.linear_struct.面试150题;

/**
 * @Author: mizy3
 * @Date: 2024/08/14/下午9:39
 * @Description:
 */
public class Pro26删除有序数组中的重复项 {

    public int removeDuplicates(int[] nums) {
        int i = 0, j = 0;
        //          i
        // [0,1,2,3,4,2,2,3,3,4]
        //                       j

        //  i
        // [1,2,2]
        //  j
        while (j < nums.length) {
            if (nums[i] == nums[j]) {
                j++;
                continue;
            }
            nums[++i] = nums[j];
        }
        return i + 1;
    }
}
